package com.mr.cai.main.fragment;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.cai.mr.lib.utils.LogInfo;
import com.mr.cai.main.R;
import com.mr.cai.main.activity.ClassifyActivity;
import com.mr.cai.main.adapter.ClassifyTitleAdapter;
import com.mr.cai.main.utils.ClassifySelPop;
import com.mr.cai.main.view.BasePopupWindow;
import com.mr.cai.main.view.HorizontallyView;

/**
 * Created by Administrator on 16-2-25.
 */
public class ClassifyTitleFragment extends BaseFragment implements ViewPager.OnPageChangeListener  {
    private HorizontallyView mHorizontallView;
    private ClassifyTitleAdapter mAdapter;
    private ImageView mTypeSelView;
    private View mView;
    private BasePopupWindow mPop;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mView=LayoutInflater.from(getActivity()).inflate(R.layout.classify_title_fg_layout,null);
        findView();
        setListener();
    }

    private void setListener() {
        mHorizontallView.setOnSelecterListener((ClassifyActivity)getActivity());
        mPop.setOnItemClickListener(itemClickListener);
        mTypeSelView.setOnClickListener(typeClick);
    }
    private View.OnClickListener typeClick=new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            LogInfo.log("lee", "onClick");
            if(!mPop.isShowing()){
                mPop.showAsDropDown(view, Gravity.CENTER,0,0);
            }else{
                mPop.dismiss();
            }

        }
    };

    BasePopupWindow.ItemClickListener itemClickListener= new BasePopupWindow.ItemClickListener()

    {
        @Override
        public void onItemClick(int position) {

        }
    };


    private void findView() {
        mHorizontallView=(HorizontallyView)mView.findViewById(R.id.titleContainer);
        mTypeSelView=(ImageView)mView.findViewById(R.id.typeSelViewMenu);
        mAdapter=new ClassifyTitleAdapter(getActivity());
        mHorizontallView.setAdapter(mAdapter);
        mHorizontallView.startAnim(0);
        mPop=new ClassifySelPop(getActivity());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return mView;
    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        mHorizontallView.startAnim(position);
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
